package user_assets

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserUpdateBankInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 更新
func NewUserUpdateBankInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserUpdateBankInfoLogic {
	return &UserUpdateBankInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserUpdateBankInfoLogic) UserUpdateBankInfo(req *types.UserUpdateBankInfoRequest) (resp *types.UserUpdateBankInfoResponse, err error) {
	_, err = l.svcCtx.AssetsRpc.UserChannel.UserBankUpdate(l.ctx, &rpc.UserBankInfoUpdateRequest{
		Id:         req.ID,
		UserId:     req.UserId,
		Username:   req.UserName,
		CardNumber: req.CardNum,
		Email:      req.Email,
		Phone:      req.Phone,
		IfscCode:   req.IFSCCode,
		BankId:     req.BankId,
		Province:   req.Province,
		City:       req.City,
		BranchBank: req.BranchBank,
	})
	if err != nil {
		return &types.UserUpdateBankInfoResponse{
			IsUpdate: false,
		}, nil
	}
	return &types.UserUpdateBankInfoResponse{
		IsUpdate: true,
	}, nil
}
